package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import com.ruoyi.system.domain.Wtgl;
import com.ruoyi.system.domain.vo.issueMap;
import com.ruoyi.web.controller.monitor.FileUploadUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Feedback;
import com.ruoyi.system.service.IFeedbackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * illustriousness.`feedback`Controller
 *
 * @author ruoyi
 * @date 2022-12-02
 */
@RestController
@RequestMapping("/system/feedback")
public class FeedbackController extends BaseController
{
    @Autowired
    private IFeedbackService feedbackService;

    /**
     * 查询illustriousness.`feedback`列表
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(issueMap issuemap)
    {
        startPage();
        List<issueMap> list = feedbackService.selwtgllist(issuemap);
        return getDataTable(list);
    }

    /**
     * 导出illustriousness.`feedback`列表
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:export')")
    @Log(title = "illustriousness.`feedback`", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Feedback feedback)
    {
        List<Feedback> list = feedbackService.selectFeedbackList(feedback);
        ExcelUtil<Feedback> util = new ExcelUtil<Feedback>(Feedback.class);
        util.exportExcel(response, list, "illustriousness.`feedback`数据");
    }

    /**
     * 获取illustriousness.`feedback`详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(feedbackService.selectFeedbackById(id));
    }

    /**
     * 新增illustriousness.`feedback`
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:add')")
    @Log(title = "illustriousness.`feedback`", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Feedback feedback)
    {
        return toAjax(feedbackService.insertFeedback(feedback));
    }

    /**
     * 修改illustriousness.`feedback`
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:edit')")
    @Log(title = "illustriousness.`feedback`", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Feedback feedback)
    {
        return toAjax(feedbackService.updateFeedback(feedback));
    }

    /**
     * 删除illustriousness.`feedback`
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:remove')")
    @Log(title = "illustriousness.`feedback`", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(feedbackService.deleteFeedbackByIds(ids));
    }

    //审批
    @PreAuthorize("@ss.hasPermi('system:feedback:upd')")
    @Log(title = "illustriousness.`feedback`", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}/{val}")
    public AjaxResult upd(@PathVariable("id") int id,@PathVariable("val")int val){
        return  toAjax(feedbackService.upd(id,val));
    }

//    //文件上传
//    @Log(title = "用户头像",businessType = BusinessType.UPDATE)
//    @PostMapping("/avatar")
//    public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception{
//        //判断图片不能为空
//        if (!file.isEmpty()){
//            //通过Security获取到登录用户信息
//            LoginUser loginUser = getLoginUser();
//            //图片完整路径
//            String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(),file, MimeTypeUtils.IMAGE_EXTENSION);
//            //保存到数据库   通过用户名查找到对应用户修改头像地址信息
//            if ()
//        }
//    }

}
